package com.baidu.dtx.order.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.baidu.dtx.order.entities.Order;
import com.baidu.dtx.order.service.OrderService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author shilei
 * @create 2021-04-19 23:16
 */
@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    @RequestMapping("/order/add")
    public String addOrder(@RequestParam("couponNo") Integer couponNo)
    {
        Order order = new Order();
        order.setUserId(1);
        order.setProductId(1);
        order.setPaymentMoney(new BigDecimal(100));
        order.setProductCount(1);
        order.setOrderNo(IdUtil.simpleUUID());

        order.setDecreaseScore(2);//扣除2个积分
        order.setCouponReceiveId(couponNo);//抵扣优惠卷

        int i = orderService.add(order);

        return "-----success add order to mysql: "+"\t"+i+"\t"+DateUtil.now();
    }
}
